package bold.storage.core;


import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class Record extends HashMap<String, Object> {

    private static final long serialVersionUID = -1218533789804830691L;

    public Record() {
    }

    public Record(String k, Object v) {
        super.put(k, v);
    }

    public Object get(Object key) {
        return super.get(key);
    }

    public Record set(String key, Object value) {
        this.put(key, value);
        return this;
    }

    public String toString() {
        String str = "";
        Set<Entry<String, Object>> set = this.entrySet();

        Entry entry;
        for (Iterator var3 = set.iterator(); var3.hasNext(); str = str + entry.getKey() + "=" + (entry.getValue() != null ? entry.getValue().toString() : "") + ";") {
            entry = (Entry) var3.next();
        }

        if (str.length() > 0) {
            str = str.substring(0, str.length() - 1) + "\r\n";
        }

        return str;
    }

    public String getString(String key) {
        return this.getString(key, null);
    }

    public String getString(String key, String defaultValue) {
        return getString(this.get(key), defaultValue);
    }

    public static String getString(Object obj, String defaultValue) {
        if (obj == null) return defaultValue;
        if (obj instanceof String) return (String) obj;
        return String.valueOf(obj);
    }

    public Integer getInteger(String key) {
        return this.getInteger(key, null);
    }

    public Integer getInteger(String key, Integer defaultValue) {
        return getInteger(this.get(key), defaultValue);
    }

    public static Integer getInteger(Object obj, Integer defaultValue) {
        if (obj == null) return defaultValue;
        if (obj instanceof Integer) return (Integer) obj;
        return Integer.valueOf(obj.toString());
    }

    public String getInteger(String key, Integer defaultValue, String pattern) {
        return this.getNumber(key, defaultValue, pattern);
    }

    public Long getLong(String key) {
        return this.getLong(key, null);
    }

    public Long getLong(String key, Long defaultValue) {
        return getLong(this.get(key), defaultValue);
    }

    public static Long getLong(Object obj, Long defaultValue) {
        if (obj == null) return defaultValue;
        if (obj instanceof Long) return (Long) obj;
        return Long.valueOf(obj.toString());
    }

    public String getLong(String key, Long defaultValue, String pattern) {
        return this.getNumber(key, defaultValue, pattern);
    }

    public Float getFloat(String key) {
        return this.getFloat(key, null);
    }

    public Float getFloat(String key, Float defaultValue) {
        return getFloat(this.get(key), defaultValue);
    }

    public static Float getFloat(Object obj, Float defaultValue) {
        if (obj == null) return defaultValue;
        if (obj instanceof Float) return (Float) obj;
        return Float.valueOf(obj.toString());
    }

    public String getFloat(String key, Float defaultValue, String pattern) {
        return this.getNumber(key, defaultValue, pattern);
    }

    public Double getDouble(String key) {
        return this.getDouble(key, null);
    }

    public Double getDouble(String key, Double defaultValue) {
        return getDouble(this.get(key), defaultValue);
    }

    public static Double getDouble(Object obj, Double defaultValue) {
        if (obj == null) return defaultValue;
        if (obj instanceof Double) return (Double) obj;
        return Double.valueOf(obj.toString());
    }

    public String getDouble(String key, Double defaultValue, String pattern) {
        return this.getNumber(key, defaultValue, pattern);
    }

    public Number getNumber(String key) {
        return (Number) this.get(key);
    }

    public Number getNumber(String key, Number defaultValue) {
        Object obj = this.get(key);
        return obj != null ? (Number) this.get(key) : defaultValue;
    }

    public String getNumber(String key, Number defaultValue, String pattern) {
        DecimalFormat df = new DecimalFormat(pattern);
        Object obj = this.get(key);
        return obj != null ? df.format(this.get(key)) : df.format(defaultValue);
    }

    public Timestamp getTimestamp(String key) {
        return (Timestamp) this.get(key);
    }

    public Timestamp getTimestamp(String key, Timestamp defaultValue) {
        Object obj = this.get(key);
        return obj != null ? (Timestamp) this.get(key) : defaultValue;
    }

    public Date getDate(String key) {
        return (Date) this.get(key);
    }

    public Date getDate(String key, Date defaultValue) {
        Object obj = this.get(key);
        return obj != null ? (Date) this.get(key) : defaultValue;
    }

    public String toJavaScriptObject() {
        StringBuilder sb = new StringBuilder("{");
        int l = sb.length();
        Iterator var3 = this.entrySet().iterator();

        while (var3.hasNext()) {
            Entry e = (Entry) var3.next();
            String key = (e.getKey()).toString().replace("\"", "\\\"");
            String value = e.getValue().toString().replace("\"", "\\\"");
            sb.append('"').append(key).append("\":\"").append(value).append("\",");
        }

        if (sb.length() > l) {
            sb.deleteCharAt(sb.length() - 1);
        }

        sb.append("}");
        return sb.toString();
    }

    public static void main(String[] args) {
        Record record = new Record("key", "12321.123123");
        System.out.println(record.getDouble("key"));
    }
}
